<template>
  <a-modal
      title="添加押金"
      :width="650"
      :visible="fyvisible"
      :confirmLoading="fyconfirmLoading"
      @cancel="fyhandleCancel"
      @ok="handleSubmit"
    >
      <a-table
        :columns="columnsFyDio"
        :data-source="loadDataFyDio"
        :rowKey="(record) => record.key"
        :row-selection="rowSelection"
        :pagination='false'>
        <span slot="type" slot-scope="text">
          {{ 'cost_type' | dictType(text) }}
        </span>
      </a-table>
    </a-modal>
</template>
<script>
  import { busCostBillHydropowerList } from '@/api/modular/main/buscostbillhydropower/busCostBillHydropowerManage'
  export default {
    data() {
      return {
        // 已保存的押金
        fyData: [],
        // 彈出框押金列表
        loadDataFyDio: [],
        // 已選擇的押金-未保存 -key
        selectedRowKeysFyDio: [],
        selectedRowsFyDio: [],
        columnsFyDio: [
          {
            title: '費用項',
            dataIndex: 'name'
          },
          {
            title: '收費方式',
            dataIndex: 'type',
            scopedSlots: { customRender: 'type' }
          }
        ],
        fyvisible: false,
        fyconfirmLoading: false
      }
    },
    computed: {
      rowSelection() {
        return {
          onChange: this.onSelectChangeFyDio,
          selectedRowKeys: this.selectedRowKeysFyDio,
          getCheckboxProps: record => ({
            props: {
              disabled: record.disabled,
              name: record.name
            }
          })
        }
      }
    },
    created() {
    },
    methods: {
      add (fyData) {
        this.fyData = fyData
        this.fyvisible = true
         busCostBillHydropowerList().then((res) => {
            const reldata = []
            if (res.code === 200) {
              if (res.data.length > 0) {
                for (var i = 0; i < res.data.length; i++) {
                  var zt = false
                  for (var im = 0; im < this.fyData.length; im++) {
                    if (res.data[i].id === this.fyData[im].key) {
                      zt = true
                      break
                    }
                  }
                  reldata.push({ key: res.data[i].id, disabled: zt, name: res.data[i].name, costid: res.data[i].id, type: res.data[i].type, amount: 0.00, solder: 0, magnification: 1, initialreading: 0, ydzd: 1 })
                }
                this.loadDataFyDio = reldata
              }
            } else {
              this.$message.error(res.msg)
            }
          })
      },
      onSelectChangeFyDio (selectedRowKeys, selectedRows) {
        this.selectedRowKeysFyDio = selectedRowKeys
        this.selectedRowsFyDio = selectedRows
      },
      handleSubmit () {
        this.$emit('ok', this.selectedRowsFyDio)
        this.fyhandleCancel()
      },
      fyhandleCancel () {
        this.selectedRowsFyDio = []
        this.selectedRowKeysFyDio = []
        this.fyData = []
        this.fyvisible = false
      }
    }
}
</script>
<style lang="less">
</style>
